def check(n):
    if n == 1:
        return False
    test = True
    k = n - 1
    while k > 1:
        if not n % k:
            test = False
            break
        k = k - 1
    return test

num = input()
r = []
for i in range(len(num)):
    for k in range(i + 1, len(num) + 1):
        n = int(num[i:k])
        if check(n):
            r = r + [n]

print(max(r) if r else 0)

